<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目档案编号">
              <j-input placeholder="请输入项目档案编号" v-model="mostImportantParams.projectNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="mostImportantParams.projectName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="研发类型">
              <j-dict-select-tag placeholder="请选择研发类型" v-model="mostImportantParams.developmentType" dictCode="development_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="甲方单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <select-Company-input placeholder="请选择甲方单位" v-model="mostImportantParams.signUnit" />
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="乙方单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!-- <select-Company-input placeholder="请选择乙方单位" v-model="mostImportantParams.supplierId" /> -->
              <select-customer-input commercialType="2" v-model="mostImportantParams.supplierId" />

            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="研发归属年度">
              <j-dict-select-tag type="list" v-model="mostImportantParams.year" dictCode="yjgsnd" placeholder="请选择归属年度"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="费用所属团队">
              <select-team-input
                    v-model="mostImportantParams.teamName"
                    :tdlx="3"
                    placeholder="请选择费用所属团队"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业务分类">
              <business-category-name-select
                v-model="mostImportantParams.categoryCode"
                placeholder="请选择业务分类"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务档案编号">
              <j-input placeholder="请输入任务档案编号" v-model="mostImportantParams.billNo"></j-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="研发人员">
              <select-user-by-dep v-model="mostImportantParams.projectMember" placeholder="请选择人员">
              </select-user-by-dep>
            </a-form-item>
          </a-col>

          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="研发年度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag
                type="list"
                v-model="mostImportantParams.statisticsYear"
                dictCode="yjgsnd"
                placeholder="请选择研发年度"
              />
            </a-form-model-item>
          </a-col> -->


          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="研发日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-range-picker
                format="YYYY-MM-DD"
                :placeholder="['开始日期', '结束日期']"
                :allowClear="false"
                v-model="vestingDay"
                @change="
                  (dates, dateStrs) => {
                    mostImportantParams.vestingDayStart = dateStrs[0]
                    mostImportantParams.vestingDayEnd = dateStrs[1]
                  }
                "
                :default-value="defaultRangePickerValue"
                :disabled-date="disabledDate"
                style="width: 100%"
              />
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="填报状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag
                v-model="mostImportantParams.fillInStatus"
                dictCode="fill_in_status"
                placeholder="请选择填报状态"
              />
            </a-form-model-item>
          </a-col>
          

          <a-col style="float: left;overflow: hidden;" :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
        <!-- 导出文件名称为‘工时报表+操作时间’ -->
        <a-button
          type="primary"
          icon="download"
          @click="downloadXML"
          :loading="exportLoading"
          :disabled="isDisabledAuth('')"
        >导出</a-button>
      </span>
    </div>
    <!-- 根据权限决定按钮是否禁用 -->
    <div class="table-operator" style="display: flow-root">
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item, index) in defColumns">
                <template v-if="item.key != 'rowIndex' && item.dataIndex != 'action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: scrollX }"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <!-- <template slot="projectName" slot-scope="text, record">
          <span @click="clickProjectName(record)" style="color: #00aaf0; cursor: pointer">{{ text }}</span>
        </template>
        <template slot="projectNo" slot-scope="text, record">
          <span @click="clickprojectNo(record)" style="color: #00aaf0; cursor: pointer">{{ text }}</span>
        </template> -->
      </a-table>
    </div>

    <erp-project-report-modal ref="viewProjectDetail" @ok="modalFormOk"></erp-project-report-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
// 根据权限来给一个布尔值，可用来控制是否禁用
import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import simpleModal from '@/components/simpleModal'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput.vue'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import BusinessCategoryNameSelect from '@/views/erp/components/BusinessCategoryNameSelect'
import {getAction} from '@/api/manage'
import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'
import moment from 'moment'

export default {
  name: 'devSchedule',
  mixins: [DisabledAuthFilterMixin, JeecgListMixin],
  components: {
    simpleModal,
    SelectTeamInput,
    SelectUserByDep,
    SelectCustomerInput,
    SelectCompanyInput,
    BusinessCategoryNameSelect,
    ErpProjectReportModal
  },
  data() {
    return {
      vestingDay:[moment().subtract(7, 'days'), moment().subtract(1, 'days')],
      type: '',
      isorter: {
        column: '',
        order: ''
      },
      dictOptions: {},
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      initDefColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          ellipsis: true,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
 
        {
          title: '项目档案编号',
          align: 'center',
          dataIndex: 'projectNo',
          width: 200,
          ellipsis: true,
          scopedSlots: {
            customRender: 'projectNo'
          }
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
          width: 400,
          ellipsis: true,
          scopedSlots: {
            customRender: 'projectName'
          }
        },
        {
          title: '研发类型',
          align: 'center',
          dataIndex: 'developmentType',
          width: 200,
          ellipsis: true
        },
        {
          title: '研发归属年度',
          align: 'center',
          dataIndex: 'year',
          width: 200,
          ellipsis: true
        },
        {
          title: '费用所属团队',
          align: 'center',
          dataIndex: 'teamName',
          width: 200,
          ellipsis: true
        },
        {
          title: '甲方单位',
          align: 'center',
          dataIndex: 'signUnit',
          width: 200,
          ellipsis: true
        },
        {
          title: '乙方单位',
          align: 'center',
          dataIndex: 'supplierId',
          width: 200,
          ellipsis: true
        },

        {
          title: '业务分类',
          align: 'center',
          dataIndex: 'categoryName',
          width: 300,
          ellipsis: true
        },

        {
          title: '任务档案编号',
          align: 'center',
          dataIndex: 'billNo',
          width: 200,
          ellipsis: true
        },
        {
          title: '研发团队',
          align: 'center',
          dataIndex: 'productTeam',
          width: 200,
          ellipsis: true
        },
        {
          title: '研发部门',
          align: 'center',
          dataIndex: 'executeDepart_dictText',
          width: 200,
          ellipsis: true
        },
        {
          title: '研发负责人',
          align: 'center',
          dataIndex: 'projectLeading',
          width: 200,
          ellipsis: true
        },
        {
          title: '任务状态',
          align: 'center',
          dataIndex: 'taskStatus',
          width: 200,
          ellipsis: true
        },
        {
          title: '任务进度(%)',
          align: 'center',
          dataIndex: 'contractRate',
          width: 200,
          ellipsis: true
        },

        {
          title: '研发人员',
          align: 'center',
          dataIndex: 'projectMember',
          width: 200,
          ellipsis: true
        },
        {
          title: '研发日期',
          align: 'center',
          dataIndex: 'productCycle',
          width: 200,
          ellipsis: true
        },
        {
          title: '研发工时',
          align: 'center',
          dataIndex: 'fillHours',
          width: 200,
          ellipsis: true
        },
        {
          title: '填报状态',
          align: 'center',
          dataIndex: 'fillInStatus',
          width: 120,
          ellipsis: true,
          // fixed: 'right'
        }

      ],
      defaultRangePickerValue:[moment().subtract(8, 'days'), moment().subtract(1, 'days')],
      url: {
        // 列表渲染
        // list: '/api/erp/hours/workmain/erpWorkingHours/queryUnFillInList',
        list: '/api/erp/hours/workmain/erpWorkingHours/queryReserchFillInList',
        // 导出接口
        // exportXlsUrl: '/api/erp/hours/workmain/erpWorkingHours/exportUnFillInXls',
        exportXlsUrl: '/api/erp/hours/workmain/erpWorkingHours/exportReserchFillInXls',
        
        // getViewProjectDetail:'/api/erp/project/report/erpProjectReport/list'
        // 项目一览表
        queryProjectById: '/api/erp/project/report/erpProjectReport/queryById'
      },
      // 不会被其他查询条件覆盖的查询参数
      mostImportantParams: {
        fillInStatus: 'no',
        isRdTask:'development',
        vestingDayStart : moment().subtract(8, 'days').format('YYYY-MM-DD'),
        vestingDayEnd : moment().subtract(1, 'days').format('YYYY-MM-DD')
      },
      workingHours: [],
      inputTaskTimeStatus: '',
      tableList: [],
      controlLoadData: true,
      controlColumns: true,
      Allmonth: 12,
      workHoursDataSource: [],
      workHoursLoading: false,
      // 导出用的参数
      exportParams: {
        choosees: []
      }
    }
  },
  created() {
    this.createColumns()
    this.loadData(1)
  },
  methods: {
    disabledDate(current) {
      return current && current >= moment().startOf('day');
    },
    downloadXML() {
      this.handleExportXls('研发工时清单'+moment().format('YYYY-MM-DD HH:mm:ss'))
    },
    // 渲染table列表头
    createColumns() {
      this.defColumns = this.initDefColumns
      this.initColumns()
    },
    // 自定义查询
    searchQuery() {
      this.onClearSelected()
      this.createColumns()
      this.loadData(1)
    },
    // 重置按钮
    searchReset() {
      this.mostImportantParams = this.$options.data().mostImportantParams
      this.workingHours = []
      // this.vestingDay = []
      this.createColumns()
      this.loadData(1)
    },
    // 点击项目名称穿透
    clickProjectName(record) {
      getAction(this.url.queryProjectById, {id: record.projectId}).then((res) => {
        if (res.success) {
          const model = res.result
          this.$refs.viewProjectDetail.getDetail(model)
          this.$refs.viewProjectDetail.title = '项目一览表'
        }
      })
    },
    clickprojectNo(record) {
      getAction(this.url.queryProjectById, {id: record.projectId}).then((res) => {
        if (res.success) {
          const model = res.result
          this.$refs.viewProjectDetail.getDetail(model)
          this.$refs.viewProjectDetail.title = '项目一览表'
        }
      })
    },


    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
      // 在此之上再将后端需要的参数传过去
      // for(let item of this.selectionRows){
      //   this.exportParams.choosees.push({
      //     // fillInUserEmpId:item.projectMember,
      //     // projectTaskId:item.projectTaskId,
      //     // projectId:item.projectId,
      //     id:item.id
      //   })
      // }
      // this.exportParams.choosees = this.exportParams.choosees.join(',')
      // this.exportParams.choosees = JSON.stringify(this.exportParams.choosees)
      // this.exportParams.choosees = {"id":3,"name":4}
      // this.exportParams.choosees1 = JSON.stringify([{id:1,name:'hahah'}])
    },
    handleDetail() {
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
